<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>Document</title>
    <script src="./lib/vue-2.4.0.js"></script>
</head>
<body>
    <div id='app'>
        <!-- 父组件向子组件传递方法，使用的是事件绑定机制 -->
        <com2 @func='show'></com2>
    </div>

    <template id='tmpl'>
        <div>
            <h1>这是子组件</h1>
            <input type="button" value="这是子组件的按钮，点击触发父组件传递过来的 func 方法" @click="myclick">
        </div>
    </template>

    <script>

        var com2 = {
            template : '#tmpl',
            data(){
                return {
                    sonmsg:{name:"小头儿子", age:6}
                }
            },
            methods : {
                myclick(){
                    // emit : 触发，调用的意思
                    //this.$emit("func", 123, 456)
                    this.$emit("func", this.sonmsg)
                }
            }
        }

        var vm = new Vue({
            el : '#app',
            data : {
                datamsgFromSon : null
            },
            methods : {
                // show(data, data2){
                //     console.log('调用父组件的show方法---' + data + ' ' + data2)
                // }

                show(data){
                    //console.log(data)
                    this.datamsgFromSon = data
                }
            },
            components :{
                com2
            }
        })

    </script>
</body>
</html>